<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1. 盛水最多的容器
        // 时间复杂度：O(n)
        // 空间复杂度：O(1)
        var maxArea = function(height) {
            let n = height.length
            let ans = 0
            let left = 0
            let right = n - 1
            while (left < right) {
                let prod = Math.min(height[left], height[right]) * (right - left)
                ans = Math.max(prod, ans)
                // 这个没想到，如果是左边的线段更短，左边的线右移，否则右边的线短就右指针左移
                if (height[left] < height[right]) {
                    left++
                } else {
                    right--
                }
            }
            return ans
        };
        console.log(maxArea([1,8,6,2,5,4,8,3,7]));
        console.log(maxArea([1, 1]));
    </script>
</body>
</html>